package com.chenjiahao.kaiyanwan.ui.search

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.chenjiahao.kaiyanwan.logic.dao.Repository
import com.hazz.kotlinmvp.mvp.model.bean.HomeBean

/**
 * Created by chenjh on 2020/9/16
 */
class SearchViewModel : ViewModel() {

    private val searchParameterLiveData = MutableLiveData<String>()

    private var nextPageUrlLiveData = MutableLiveData<String>()

    var nextPageUrl:String?=null

    var stringList=ArrayList<String>()

    var itemList = ArrayList<HomeBean.Issue.Item>()

    private val hotLiveData = MutableLiveData<Any?>()
    val searchData = Transformations.switchMap(searchParameterLiveData) {
        Repository.getSearchData(it)
    }

    val IssueData =Transformations.switchMap(nextPageUrlLiveData){
        Repository.getIssueData(it)
    }

    val hotData = Transformations.switchMap(hotLiveData) {
        Repository.getHotWord()
    }

    //获取搜索数据
    fun requestSearchData(paramString: String) {
        searchParameterLiveData.value = paramString
    }

    //获取热门词
    fun getHotData() {
        hotLiveData.value = hotData.value
    }

    fun requestMoreData(){
        nextPageUrlLiveData.value=nextPageUrl
    }

}